-- ********************************************
-- * Copyright (c) 2012 TPV R&D Center Brazil *
-- * All Rights Reserved                      *
-- ********************************************

--- toolkit.component.IndexPage

local IndexPage = Box:new()

function IndexPage:new(o)
   if (type(o) ~= 'table') then
      o = {}
   end

local newIndexPage = Box:new(o)

   newIndexPage.parent = nil
   
   newIndexPage.content = nil

   newIndexPage.componentType = "IndexPage"

   newIndexPage.selected = o.selected or 1 -- is default

   newIndexPage.maxPage = o.maxPage or 1
   
   newIndexPage.activePage = o.activePage or nil
   newIndexPage.disabledPage = o.disabledPage or nil

   newIndexPage.numberPages = o.numberPages or 1

   --generate an object
   setmetatable(newIndexPage, self)
   self.__index = self

   return newIndexPage
end

function IndexPage:setNumberPage(nPages)
   if (nPages < 1) then nPages = 1 end
   self.numberPages = nPages
   self.parent:updateIndexPage(self)
end

function IndexPage:setPageFocus(nSelection)
   if (nSelection < 1) then 
      nSelection = 1
   elseif (nSelection > self.numberPages) then 
      nSelection = self.numberPages 
   end
   self.selected = nSelection
   self.parent:updateIndexPage(self)
end

function IndexPage:redraw()
  self.parent:updateIndexPage(self)
end

function IndexPage:dispose()
   self.activePage = nil
   self.disabledPage = nil
   collectgarbage()
end

return IndexPage
